package com.qcby.ssm.controller;

import com.qcby.ssm.pojo.Emp;
import com.qcby.ssm.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class EmpController {
    @Autowired
    private EmpService empService;

    @RequestMapping("/findAllEmp")
    public ModelAndView returnAll(){
        List<Emp> allEmp = empService.findAllEmp();
        ModelAndView modelAndView = new ModelAndView();
        System.out.println(allEmp);
        modelAndView.addObject(allEmp);
        modelAndView.setViewName("employee");
        return modelAndView;
    }

    @RequestMapping(value = "/findEmpById/{id}",method = RequestMethod.GET,params = {"id","id=123","password!=123","!email"})
    public ModelAndView findEmpById(@PathVariable("id") Integer id){
        System.out.println(id);
        Emp emp = empService.findEmpById(id);
        ModelAndView modelAndView = new ModelAndView();
        System.out.println(emp);
        modelAndView.addObject(emp);
        modelAndView.setViewName("employee");
        return modelAndView;
    }

    public String deleteEmp(@PathVariable("id") Integer id){
      return "";
    }

    @RequestMapping(value="/deleteEmp",method = RequestMethod.GET)
    public String deleteEmp(){
        return "";
    }
}
